# Copyright (c) 2025 Huawei Technologies Co., Ltd.
# This file is a part of the CANN Open Software.
# Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# ======================================================================================================================

add_ops_compile_options(
    OP_NAME MatmulAllReduce
    OPTIONS --cce-auto-sync=off
            -Wno-deprecated-declarations
            -Werror
)

set(matmul_all_reduce_depends
    mc2/mat_mul_v3
    mc2/quant_batch_matmul_v3
    mc2/weight_quant_batch_matmul_v2
    mc2/common
    PARENT_SCOPE)

target_sources(op_host_aclnnExc PRIVATE
    matmul_all_reduce_def.cpp
)

target_include_directories(opapi PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/../../common
    ${CMAKE_CURRENT_SOURCE_DIR}/../../common/ophost
    ${CMAKE_CURRENT_SOURCE_DIR}/../../mat_mul_v3
    ${CMAKE_CURRENT_SOURCE_DIR}/../../quant_batch_matmul_v3
    ${CMAKE_CURRENT_SOURCE_DIR}/../../weight_quant_batch_matmul_v2
)

target_sources(opapi PRIVATE
    aclnn/aclnn_matmul_all_reduce.cpp
    aclnn/aclnn_matmul_all_reduce_v2.cpp
    aclnn/aclnn_quant_matmul_all_reduce.cpp
    aclnn/aclnn_quant_matmul_all_reduce_v2.cpp
    aclnn/aclnn_quant_matmul_all_reduce_v3.cpp
    aclnn/aclnn_weight_quant_matmul_all_reduce.cpp
    aclnn/matmul_all_reduce_util.cpp
)

if (NOT BUILD_OPEN_PROJECT)
    target_sources(opmaster_ct PRIVATE
        tiling/all_reduce_formulaic_tiling.cpp
        tiling/matmul_all_reduce_tiling_910.cpp
        tiling/matmul_all_reduce_tiling.cpp
        tiling/quant_matmul_all_reduce_tiling.cpp
        tiling/weight_quant_matmul_all_reduce_tiling.cpp
    )
endif ()

target_include_directories(optiling PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/../../common
    ${CMAKE_CURRENT_SOURCE_DIR}/../../common/ophost/matmul_tiling
    ${CMAKE_CURRENT_SOURCE_DIR}/../../mat_mul_v3
    ${CMAKE_CURRENT_SOURCE_DIR}/../../quant_batch_matmul_v3
    ${CMAKE_CURRENT_SOURCE_DIR}/../../weight_quant_batch_matmul_v2
    ${ASCEND_CANN_PACKAGE_PATH}/include/experiment
)

target_sources(opsproto PRIVATE
    matmul_all_reduce_proto.cpp
)
target_include_directories(opsproto PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/../../common
    ${CMAKE_CURRENT_SOURCE_DIR}/../../common/ophost
    ${CMAKE_CURRENT_SOURCE_DIR}/../../common/ophost/matmul_tiling
)

file(GLOB _matmul_all_reduce_aclnn_header "aclnn*matmul_all_reduce*.h")

install(FILES ${_matmul_all_reduce_aclnn_header}
    DESTINATION ${ACLNN_INC_INSTALL_DIR} OPTIONAL
)